package MainComponent;
import java.io.File;
import java.util.ArrayList;

import dataobj.*;

/***
 * Create the timetable in the ICS file.
 */
public class TimetableCreator {

	private ICSGenerator generator;
	private CourseOperate operate;
	private ConfigTO config;
	
	/***
	 * Class constructor specifying the config.
	 * @param config	the config
	 */
	public TimetableCreator(ConfigTO config){
		this(config, new ICSGenerator(), new CourseOperate(config.getUniversity()));
	}
	
	/***
	 * Class constructor specifying the config, ICS file generator and the course operator.
	 * @param config	the config
	 * @param generator	the ICS file generator
	 * @param co		the course operator
	 */
	private TimetableCreator(ConfigTO config, ICSGenerator generator, CourseOperate co){
		this.config = config;
		this.generator = generator;
		this.operate = co;
	}
	
	/***
	 * Create the timetable with the store path and name.
	 * @return		the ICS file generator
	 */
	public boolean createTimeTable() {
		File file = new File(config.getFilePath());
		ArrayList<CourseTO> courses = operate.getCourses(file);

		if(courses.size() != 0){
			config.setStorePath("");
			config.setStoreName();
			return generator.createICSByCourses(courses, config.getUniversity(), config.getICSLocation());
		}else
			return false;
	}
}
